package graphique;


//import Panneau;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;

import executer.Controleur;


public class BarreMenu extends JFrame implements ActionListener{
	
	//Fenetre pan = new Fenetre();
    public JMenuBar menuBar = new JMenuBar();
	
    private JMenu fichier = new JMenu("Fichier");
    private JMenu edition = new JMenu("Edition");
    //private JMenu option = new JMenu("Options");
    private JMenu aide = new JMenu("?");
    //private JMenu affichage = new JMenu("Affichage du Calendrier");
    private JMenuItem ajouContact = new JMenuItem("Ajouter Contact...");
    private JMenuItem exporterC = new JMenuItem("Exporter Contacts...");

    private JMenuItem deconnexion = new JMenuItem("Deconnexion...");
    private JMenuItem quitter = new JMenuItem("Quitter");
    private JMenuItem guide = new JMenuItem("Aides...");
    private JMenuItem aPropos = new JMenuItem("A Propos...");
    //private JMenuItem config = new JMenuItem("Configuration...");
    
    private JRadioButtonMenuItem mois = new JRadioButtonMenuItem("Mois");
    private JRadioButtonMenuItem semaine = new JRadioButtonMenuItem("Semaine");
    private JRadioButtonMenuItem gererContact = new JRadioButtonMenuItem("Gerer Contacts");
    //private JRadioButtonMenuItem ajouContact = new JRadioButtonMenuItem("ajouter Contact");
    private JRadioButtonMenuItem supContact = new JRadioButtonMenuItem("Supprimer Contact");
    
    private ButtonGroup bg1 = new ButtonGroup();
    private ButtonGroup bg2 = new ButtonGroup();
    
    private Controleur c;
    
	public BarreMenu(Controleur c){
		super();
		this.c = c;
	}
	
	public JMenuBar CreationBarMenu(){
        //Menu fichier
		
		deconnexion.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
    			new Connection(c);
    		}
		});
        
    	fichier.add(deconnexion);
        
    	quitter.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent event){
    			System.exit(0);
    		}
    	});
    	fichier.add(quitter);
    	
    	//Menu edition
    	bg1.add(mois);
    	bg1.add(semaine);
    	//bg2.add(gererContact);
    	ajouContact.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent event){
    			new FormulaireContact("Nouveau Contact", c);
    		}
    	});
    	
    	exporterC.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent event){
    			boiteExport();
    			c.exporterContact();
    		}
    	});
    	
    	//bg2.add(ajouContact);
    	//bg2.add(supContact);
    	
        
        //affichage.add(mois);
    	//affichage.add(semaine);
    	/*contact.add(gererContact);
    	contact.add(ajouContact);
    	contact.add(supContact);*/
    	
    	
    	//edition.add(affichage);
    	edition.add(ajouContact);
    	edition.add(exporterC);
    	
    	//menu option
    	//option.add(config);
    	
    	//menu ?
    	
    	guide.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent event){
    			boiteGuide();
    		}
    	});
       
    	aide.add(guide);
        
        aPropos.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent event){
    			boiteApropos();
    		}
    	});
        aide.add(aPropos);
    	
    	//Ajout des menus dans la barre de menus
    	menuBar.add(fichier);
    	menuBar.add(edition);
    	//menuBar.add(option);
    	menuBar.add(aide);
    	
    	//Ajout de la barre de menus sur la fenêtre
    	//setJMenuBar(menuBar); 
        return menuBar;
    }

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	private void boiteApropos()
    {
        JFrame f = new JFrame("A propos");
        f.setSize(300, 300);
        f.setLocationRelativeTo(null);
		f.setResizable(false);
        JPanel p = new JPanel();
        JLabel l1 = new JLabel("Agenda Electronique");
        JLabel l2 = new JLabel("MIF16   Conduite de projet");
        JLabel l4 = new JLabel("Mbengue Moustapha");
        JLabel l3 = new JLabel("Mom Sarinna");
        JLabel l5 = new JLabel("Ndaw Awa");
        JLabel l6 = new JLabel("Peycelon Adeline");
        JLabel l7 = new JLabel("Pina Nicolas");
        JLabel l8 = new JLabel("Amina");
        Box vBox = Box.createVerticalBox();
        vBox.add(l1);
        vBox.add(Box.createVerticalStrut(5));
        vBox.add(l2);
        vBox.add(Box.createVerticalStrut(30));
        vBox.add(l3);
        vBox.add(Box.createVerticalStrut(5));
        vBox.add(l4);
        vBox.add(Box.createVerticalStrut(5));
        vBox.add(l5);
        vBox.add(Box.createVerticalStrut(5));
        vBox.add(l6);
        vBox.add(Box.createVerticalStrut(5));
        vBox.add(l7);
        vBox.add(Box.createVerticalStrut(5));
        vBox.add(l8);
        p.add(vBox);
        f.add(p);
        f.setVisible(true);
    }
	
	private void boiteExport()
    {
        JOptionPane.showMessageDialog(null, 
                                      "Exportation de la liste des contacts",
                                      "Info", 
                                      JOptionPane.INFORMATION_MESSAGE);
    }
	
	private void boiteGuide()
    {
        JOptionPane.showMessageDialog(null, 
                                      "Fonctionnalite non disponible",
                                      "Erreur", 
                                      JOptionPane.ERROR_MESSAGE);
    }

}
